
import { Component, Input, OnInit } from '@angular/core';
import { NzModalSubject } from 'ng-zorro-antd';
import { Jsonp, Response, Http } from '@angular/http';
import { Observable } from 'rxjs/Observable';
import 'rxjs/add/operator/map';


@Component({
  selector: 'ree-select',
  templateUrl: './select.component.html',
  styles: [
    `
    :host ::ng-deep .customize-footer {
      border-top: 1px solid #e9e9e9;
      padding: 10px 18px 0 10px;
      text-align: right;
      border-radius: 0 0 0px 0px;
      margin: 15px -16px -5px -16px;
    }
  `
  ],
  providers: []
})

export class SelectComponent implements OnInit {
  _type: string;
  selectedOption;
  searchOptions = [];
  showInfo: boolean = false;
  companyName: string = '吃饭公司';
  companyAd: string = '人民大食堂';

  @Input()
  set type(value: string) {
    this._type = value;
  }

  constructor(
    private subject: NzModalSubject,
    private http: Http,
  ) {
    this.subject.on('onDestory', () => {
      console.log('destroy');
    });
  }

  ngOnInit() {
    console.log(this._type)
  }

  outWithData() {
    sessionStorage.setItem('create_companyName', this.companyName);
    sessionStorage.setItem('create_companyAd', this.companyAd);
    this.out();
  }

  out() {
    this.subject.destroy('onCancel');   
    this.subject.next('skip'); 
  }
  /*  handleCancel(e) {
     this.subject.destroy('onCancel');
   } */

  //下拉框关闭时请求公司信息并显示
  nzOpenChange(e) {
    if (e === false && this.selectedOption !== undefined) {
      this.showInfo = true
    }
  }

  searchChange(searchText) {
    (this.http.get('assets/mock-data/companyName.json')
      .map(res => res.json()) as Observable<Response>)
      .subscribe((data: any) => {
        this.searchOptions = data.data;
      });
  }

}